﻿using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace Masterduner.SourceStudio.Practices.DevelopmentLibrary.Utilities.DataConfiguration.Controls
{
    public partial class BrowseButton : UserControl
    {
        private FileInfo _selectedConfigurationFile;

        #region SelectedConfigurationFile
        public FileInfo SelectedConfigurationFile
        {
            get { return _selectedConfigurationFile; }
            private set { _selectedConfigurationFile = value; }
        }
        #endregion

        public BrowseButton()
        {
            InitializeComponent();
        }

        #region BrowseButton_Load
        private void BrowseButton_Load(object sender, EventArgs e)
        {
            this.SetBrowseButtonBackgroundColor();
        }
        #endregion

        #region SetBrowseButtonBackgroundColor
        private void SetBrowseButtonBackgroundColor()
        {
            this.btnBrowse.BackColor = ColorTranslator.FromHtml("#028760");
        }
        #endregion

        #region btnBrowse_Click
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (this.dialogBrowseConfigFile.ShowDialog() == DialogResult.OK)
            {
                this.SelectedConfigurationFile = new FileInfo(this.dialogBrowseConfigFile.FileName);
                this.RaiseEvent();
            }
        }
        #endregion

        public event EventHandler AfterSelected;

        #region RaiseEvent
        private void RaiseEvent()
        {
            if (AfterSelected.NotIsNull())
                AfterSelected(this, new EventArgs());
        }
        #endregion
    }
}
